<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of plus</title>
  <meta name="keywords" content="plus">
  <meta name="description" content="A=B+C">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="#">tt2</a> &gt; <a href="index.html">@tt_tensor</a> &gt; plus.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for tt2/@tt_tensor&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>plus
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>A=B+C</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [a]=plus(b,c) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">A=B+C
   [A]=PLUS(B,C)  Adds two TT-tensors B and C


 TT-Toolbox 2.2, 2009-2012

This is TT Toolbox, written by Ivan Oseledets et al.
Institute of Numerical Mathematics, Moscow, Russia
webpage: http://spring.inm.ras.ru/osel

For all questions, bugs and suggestions please mail
ivan.oseledets@gmail.com
---------------------------</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="../../tt2/@qtt_tucker/dot.html" class="code" title="function [p] = dot(qt1,qt2, do_qr)">dot</a>	Dot product of two QTT-Tuckers</li><li><a href="../../tt2/@tt_matrix/dot.html" class="code" title="function [p] = dot(tt1,tt2)">dot</a>	Frobenius dot product of two TT-matrices</li><li><a href="dot.html" class="code" title="function [p] = dot(tt1,tt2,do_qr)">dot</a>	Dot  product of two TT tensors</li><li><a href="reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>	Reshape of the TT-tensor</li><li><a href="tt_tensor.html" class="code" title="function t = tt_tensor(varargin)">tt_tensor</a>	TT-tensor constructor</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [a]=plus(b,c)</a>
0002 <span class="comment">%A=B+C</span>
0003 <span class="comment">%   [A]=PLUS(B,C)  Adds two TT-tensors B and C</span>
0004 <span class="comment">%</span>
0005 <span class="comment">%</span>
0006 <span class="comment">% TT-Toolbox 2.2, 2009-2012</span>
0007 <span class="comment">%</span>
0008 <span class="comment">%This is TT Toolbox, written by Ivan Oseledets et al.</span>
0009 <span class="comment">%Institute of Numerical Mathematics, Moscow, Russia</span>
0010 <span class="comment">%webpage: http://spring.inm.ras.ru/osel</span>
0011 <span class="comment">%</span>
0012 <span class="comment">%For all questions, bugs and suggestions please mail</span>
0013 <span class="comment">%ivan.oseledets@gmail.com</span>
0014 <span class="comment">%---------------------------</span>
0015 
0016 <span class="keyword">if</span> ( isempty(b) )
0017  a=c;
0018  <span class="keyword">return</span>
0019 <span class="keyword">elseif</span> ( isempty(c) )
0020  a=b;
0021  <span class="keyword">return</span>
0022 <span class="keyword">end</span>
0023 
0024 <span class="keyword">if</span> (b.d==1)&amp;&amp;(c.d==1)
0025     a = b;
0026     a.core = b.core + c.core;
0027     <span class="keyword">return</span>;
0028 <span class="keyword">end</span>;
0029 
0030 a=<a href="tt_tensor.html" class="code" title="function t = tt_tensor(varargin)">tt_tensor</a>;
0031 n1=b.n;
0032 r1=b.r;
0033 r2=c.r;
0034 d=b.d;
0035 cr1=b.core;
0036 cr2=c.core;
0037 <span class="comment">%Determine size of the result</span>
0038 r=r1+r2;
0039 <span class="keyword">if</span> ( r1(1) == r2(1) )
0040     r(1)=r1(1);
0041 <span class="keyword">else</span>
0042   error(<span class="string">'Inconsistent sizes in mode 1'</span>);    
0043 <span class="keyword">end</span>
0044 <span class="keyword">if</span> ( r1(d+1) == r2(d+1) )
0045   r(d+1)=r1(d+1);
0046 <span class="keyword">else</span>
0047   error(<span class="string">'Inconsistent sizes in the last mode'</span>);    
0048 <span class="keyword">end</span>
0049 n=n1;
0050 a.d=d;
0051 a.n=n;
0052 a.r=r;
0053 sz=<a href="dot.html" class="code" title="function [p] = dot(tt1,tt2,do_qr)">dot</a>(n.*r(1:d),r(2:d+1));
0054 pos=(n.*r(1:d)).*r(2:d+1);
0055 pos=cumsum([1;pos]);
0056 a.ps=pos;
0057 cr=zeros(sz,1);
0058 pos1=b.ps; pos2=c.ps;
0059 <span class="keyword">for</span> i=1:d
0060   pp=zeros(r(i),n(i),r(i+1));
0061   p1=cr1(pos1(i):pos1(i+1)-1);
0062   p2=cr2(pos2(i):pos2(i+1)-1);
0063   p1=<a href="reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(p1,[r1(i),n(i),r1(i+1)]);
0064   p2=<a href="reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(p2,[r2(i),n(i),r2(i+1)]);
0065   pp(1:r1(i),:,1:r1(i+1))=p1;
0066   pp(r(i)-r2(i)+1:r(i),:,r(i+1)-r2(i+1)+1:r(i+1))=p2;
0067   cr(pos(i):pos(i+1)-1)=pp(:);
0068 <span class="keyword">end</span>
0069 a.core=cr;
0070 <span class="keyword">return</span>
0071 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Wed 08-Feb-2012 18:20:24 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>